//
//  WaterFallView.h
//  CommonUI
//  瀑布流组件
//  Created by winston on 12-10-9.
//  Copyright (c) 2012年 appfactory. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@protocol WaterFallCellDelegate <NSObject>

@property (nonatomic, retain) NSString *reuseIdentifier;

@end


@class WaterFallView;
@protocol WaterFallViewDelegate <UIScrollViewDelegate>

@required
- (NSInteger)numberOfCellsInWaterFallView:(WaterFallView *)wfview;
- (NSInteger)numberOfColumnsInWaterFallView:(WaterFallView *)wfview;
- (UIView<WaterFallCellDelegate> *)waterFallView:(WaterFallView *)wfview cellAtIndex:(NSInteger)index;
- (CGFloat)waterFallView:(WaterFallView *)wfview heightForCellAtIndex:(NSInteger)index;

@optional

- (UIView *)headerForWaterFallView:(WaterFallView *)wfview;
- (UIView *)footerForWaterFallView:(WaterFallView *)wfview;

//当添加Cell时调用
- (void)waterFallView:(WaterFallView *)wfview willDisplayCell:(UIView<WaterFallCellDelegate> *)cell forIndex:(NSInteger)index;
//当移除Cell时调用
- (void)waterFallView:(WaterFallView *)wfview didBackupCell:(UIView<WaterFallCellDelegate> *)cell forIndex:(NSInteger)index;
@end


@interface WaterFallCellInfo : NSObject
{
    CGRect frame;           //frame信息
    NSUInteger index;       //索引
    NSUInteger column;      //属于那列
    NSString  *reuseID;     //重用标示
}

@property(nonatomic) CGRect frame;
@property(nonatomic) NSUInteger index;
@property(nonatomic) NSUInteger column;
@property(nonatomic,retain) NSString * reuseID;

@end

#define DEFAULTCOLUMNTMARGIN 15.0
#define DEFAULTROWMARGIN     15.0
#define TAGSEED              1000

@interface WaterFallView : UIScrollView<UIScrollViewDelegate>
{
    CGFloat columnMargin;      //水平方向间隙
    CGFloat cellMargin;        //垂直方向间隙
    CGFloat columnWidth;       //列宽
    
    CGFloat *colsMaxHeight;    //每列当前最大高度
    CGFloat *colsOriginX;      //每列左起始坐标
    
    NSInteger cellCount;       //cell的数量
    
    NSMutableArray *infoForCells;
    NSMutableDictionary *cellCache;
    NSSet *visibleCellInfo;
    
    UIView * headerView;
    UIView * footerView;
    id<WaterFallViewDelegate> wfDelegate;
}

@property(nonatomic) CGFloat columnMargin;
@property(nonatomic) CGFloat cellMargin;
@property(nonatomic,assign) id<WaterFallViewDelegate> wfDelegate; 

- (void)reloadData;  //重新加载或者内容有变更时使用
- (void)appendData;  //在后面追加cell时使用，性能优于reloadData

- (id<WaterFallCellDelegate>)dequeueReusableCellWithIdentifier:(NSString *)identifier;

@end
